#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 100010;
int n, m;
int v[N], p[N], f[N];

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		int a, b, s; cin >> b >> a >> s;
		for (int j = 1; j <= s; j <<= 1) {
			v[++cnt] = j * a;
			p[cnt] = j * b;
			s -= j;
		}
		if (s) {
			v[++cnt] = s * a;
			p[cnt] = s * b;
		}
	}
	for (int i = 1; i <= cnt; i++) {
		for (int j = m; j >= v[i]; j--) {
			f[j] = max(f[j], f[j - v[i]] + p[i]);
		}
	}
	cout << f[m] << endl;
	return 0;
}